package com.holy.sh.couviewholy.pic;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;

import com.holy.sh.couviewholy.R;

/**
 * Holy Email :victorhhl@163.com
 * Create by Holy on 2019/8/12
 * Description :印章函数shader
 * mPaint.setShader   三种模式  RePeat  Mirror Clamp （用边缘色彩填充多余空间）
 */
public class ShaderPicView extends View {
    private Paint mPaint;
    private Bitmap mBitmap;
    public ShaderPicView(Context context) {
        super(context);
        initOP();
    }

    public ShaderPicView(Context context,  AttributeSet attrs) {
        super(context, attrs);
        initOP();
    }

    public ShaderPicView(Context context,  AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initOP();
    }
    private void initOP() {
         mPaint = new Paint();
                //mPaint.setColor(Color.BLACK);
               // mPaint.setStyle(Paint.Style.STROKE);
               // mPaint.setStrokeWidth(2);
               // mPaint.setAntiAlias(true);
               // mPaint.setStrokeMiter(90);//设置画笔倾斜度
                //mPaint.setPathEffect();//设置路径样式 CopmosePathEffect-》》合并路径类型用的
                // CornerPathEffect，DashPathEffect，DiscreteOathEffect，pathDashPathEffect,SumpathEffect
                //mPaint.setStrokeCap(); Cap.ROUND`SQUARE`BUTT
                //mPaint.setStrokeJoin(Paint.Join.BEVEL); //设置路径转角样式 MITER·ROUND·BEVEL
                //mPaint.setDither(true);//抗抖动，颜色丰富无法显示，过度显示马赛克相邻像素中间插入过渡值

                //Paint 字体相关
                //mPaint.setTextSize();
                mPaint.setFakeBoldText(false);//加粗
                mPaint.setStrikeThruText(false);//删除线
                mPaint.setUnderlineText(false);//下划线
                //mPaint.setTextAlign(false);//开始绘图点位置？
                //mPaint.setTextScaleX();//设置水平拉伸
                //mPaint.setTextSkewX();//设置水平斜度
                //mPaint.setTypeface();设置字体样式

        mBitmap=BitmapFactory.decodeResource(getResources(), R.mipmap.logo);
        mPaint.setShader(new BitmapShader(mBitmap, Shader.TileMode.MIRROR, Shader.TileMode.MIRROR));

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawRect(0,0,getWidth(),getHeight(),mPaint);
    }
}
